package link.anyauto.study;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.LinearGradient;
import android.graphics.Paint;
import android.graphics.RectF;
import android.graphics.Shader;
import android.graphics.SweepGradient;
import android.util.AttributeSet;
import android.view.View;

/**
 * Created by LYQ on 2016/7/22.
 */
public class CustView extends View {
    public CustView(Context context) {
        super(context);
    }

    public CustView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public CustView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onDraw(Canvas canvas1) {
        super.onDraw(canvas1);

        Canvas canvas = new Canvas(bitmap);

        Paint paint = new Paint();
        paint.setAntiAlias(true);
//        paint.setShader(new LinearGradient(0, 0, 100, 100, new int[]{Color.RED, Color.GREEN, Color.BLUE, Color.CYAN, Color.YELLOW},
//                new float[]{0, 0.2f, 0.4f, 0.6f, 1}, Shader.TileMode.REPEAT));
        paint.setShader(new SweepGradient(getWidth()/2, getHeight()/2, new int[]{Color.RED, Color.GREEN, Color.BLUE, Color.CYAN, Color.YELLOW, Color.RED},
                new float[]{0, 0.2f, 0.4f, 0.6f, 0.8f, 1}));

//        canvas.drawArc(0, 0, 100, 100, 0, 90, true, paint);
        paint.setStyle(Paint.Style.STROKE);
        paint.setStrokeWidth(10);

        canvas.drawArc(new RectF(10, 10, 190, 190), 0, 360, false, paint);
//        canvas.drawCircle(getWidth()/2, getHeight()/2, getWidth()/2, paint);
        canvas1.drawBitmap(bitmap, 0, 0, paint);
    }

    Bitmap bitmap = Bitmap.createBitmap(200, 200, Bitmap.Config.ARGB_8888);
}
